<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="lib/jquery-3.2.1.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            height: 1000px;
        }
        .nav{
            position:fixed;
            width:100%;
            height:50px;
            background-color: red;
            opacity: 0;
        }
    </style>
</head>
<body>
    <div class="nav"></div>

    <script>
        $(window).scroll(function(){
            var scrollTop = $(window).scrollTop()
            // console.log(scrollTop)
            var opacity = scrollTop/200;
            if(opacity>1){
                opacity=1
            }
            $(".nav").css({
                opacity:opacity
            })
        })
    </script>
</body>
</html>